﻿#pragma once
#include "ADFGlobal.h"
#include "AsPluginTableModelRow.h"
#include <QAbstractTableModel>
#include <QReadWriteLock>
#include <QColor>

class ADF_EXPORT AsPluginTableModel : public QAbstractTableModel {
public:
	AsPluginTableModel();
	~AsPluginTableModel();

private:
	QVector<AsPluginTableModelRow*>	m_vpRows;
	AsPluginTableModelRow*			m_pTitleRow;

public:
	void setShowTime(bool bShowTime);
	void setShowResult(bool bShowResult);
	void setShowFilePath(bool bShowFilePath);
	inline void setShowIndex(bool bShowIndex) { m_isShowIndex = bShowIndex; }

	void refresh();			//刷新数据
	int rowCount(const QModelIndex& parent) const override;
	int columnCount(const QModelIndex& parent) const override;
	QVariant data(const QModelIndex& index, int role) const override;
	QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

	void clearRows();
	void addRow(AsPluginTableModelRow* pRow);
	void addRows(const QVector<AsPluginTableModelRow*>& pRows);		//批量添加
	void setTitleRow(AsPluginTableModelRow* pRow);
	AsPluginTableModelRow* getItem(int row)const;

	int getTotalCount()const;
	int getNGCount()const;
	int getOKCount()const;

private:
	void releaseRows();
	void releaseTitleRow();
	QString formatResult(int iResult)const;
	QBrush getResultColor(int iResult)const;

	bool m_isShowIndex;
	bool m_isShowResult;
	bool m_isShowTime;
	bool m_isShowFileName;
	QReadWriteLock m_lock;
};


